// pages/videoDetails/common/list.js
const Controller = require('../../controllers/controllers.js').controller;
const formatTime = require('../../../utils/util.js').formatTime_3;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    lessonId: {
      type: Number,
      value: ''
    },
    categoryId: {
      type: Number,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    list: [],
    page: 1,
    pageSize: 10,
    lastPage: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //获取列表
    getList() {
      Controller.contentlist({
        page: this.data.page,
        pageSize: this.data.pageSize,
        orderBy: 1,
        lessonId: this.properties.lessonId,
      }).then(res => {
        if (res.code == 0) {
          let list = this.data.list
          let lastPage = res.data.baseData.lastPage
          list = list.concat(res.data.baseData.list)
          list.forEach(item => {
            console.log(item.createTime)
            item.time = formatTime(item.createTime, '')
          });
          this.setData({
            list,
            lastPage
          })
        }
      })
    },

    //跳转
    goDetails(e) {
      let id = e.currentTarget.dataset["id"]
      wx.navigateTo({ url: '/pages/videoDetails/videoDetails?id=' + id });
    },

    //分页
    load() {
      if (this.data.lastPage) {
        return
      }
      this.setData({
        page: this.data.page + 1
      })
      this.getList()
    }
  },

  ready: function () {
    this.getList()
  }
})
